<template>
  <!-- <el-tabs :tab-position="tabPosition" style="height: 730px"> -->
  <el-tabs :tab-position="tabPosition">
    <el-tab-pane>
      <span slot="label" class="tabsLabel">账户信息</span>
      <el-form :inline="true" :model="userFormInline" ref="userFormInline" label-width="80px" class="demo-ruleForm" hide-required-asterisk>
        <el-divider content-position="left">账户信息</el-divider>
        <el-form-item prop="F_PKTL_User" :rules="userNameRules">
          <span slot="label" class="formLabel">用户名:</span>
          <el-input v-model="userFormInline.F_PKTL_User" class="formLabelInput" :disabled="true" placeholder="用户名" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_PassWord" :rules="userPasswordRules">
          <span slot="label" class="formLabel">密码:</span>
          <el-input v-model="userFormInline.F_PKTL_PassWord" type="password" class="formLabelInput" :disabled="this.personalInputDisabled1" show-password placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item prop="userPasswordCheck" :rules="userPasswordTrueRules" v-if="!this.personalInputDisabled1">
          <span slot="label" class="formLabel">确认密码:</span>
          <el-input v-model="userFormInline.userPasswordCheck" type="password" class="formLabelInput" show-password placeholder="确认密码"></el-input>
        </el-form-item>

        <br />
      </el-form>
      <el-popover placement="top" width="160" v-model="visible1">
        <p>确认修改账户信息吗？</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="text" @click="visible1 = false">取消</el-button>
          <el-button type="primary" size="mini" @click="onUserSubmit('userFormInline')">确定</el-button>
        </div>
        <el-button slot="reference" class="subButton" type="primary" :disabled="personalInputDisabled1">保存</el-button>
      </el-popover>
      <el-button class="subButton" @click="onPersonalEditor1">编辑</el-button>
      <el-button class="subButton" @click="pageReload()">取消</el-button>
    </el-tab-pane>

    <!-- 企业信息 -->
    <el-tab-pane>
      <span slot="label" class="tabsLabel">基本信息</span>
      <span v-if="FirmFormInline.F_PKTL_UserType != '0' && FirmFormInline.F_PKTL_UserType != '1'"> 账户类型错误 </span>
      <el-form :inline="true" :model="FirmFormInline" ref="FirmFormInline" v-if="FirmFormInline.F_PKTL_UserType == '1'" label-width="110px" class="demo-form-inline">
        <el-divider content-position="left">基本信息</el-divider>
        <el-form-item prop="F_PKTL_CardID" :rules="cardIDRules">
          <span slot="label" class="formLabel">身份证号码:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CardID" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="身份证号码"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_ContactAddress" :rules="addressRules">
          <span slot="label" class="formLabel">联系地址:</span>
          <el-input v-model="FirmFormInline.F_PKTL_ContactAddress" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="联系地址"></el-input>
        </el-form-item>
        <el-divider content-position="left">联系方式</el-divider>
        <el-form-item prop="F_PKTL_CurrentUserName" :rules="userNameRules">
          <span slot="label" class="formLabel">联系人姓名:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CurrentUserName" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="联系人姓名"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_CurrentUserPhone" :rules="PhoneNumberRules">
          <span slot="label" class="formLabel">手机号:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CurrentUserPhone" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_CurrentUserMail" :rules="mailRules">
          <span slot="label" class="formLabel">邮箱:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CurrentUserMail" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="邮箱"></el-input>
        </el-form-item>
        <el-divider content-position="left">附件</el-divider>
        <el-form-item label-width="formLabelWidth">
          <el-upload class="upload-class" ref="fileUpload" action="#" name="身份证附件" :file-list="fileList" :http-request="fileUpload" :on-remove="handleRemove" :disabled="this.personalInputDisabled2" >
            <el-button size="small" type="primary" :disabled="this.personalInputDisabled2">身份证附件</el-button>
          </el-upload>
        </el-form-item>

      </el-form>

      <el-form :inline="true" :model="FirmFormInline" ref="FirmFormInline" v-if="FirmFormInline.F_PKTL_UserType == '0'" label-width="110px" class="demo-form-inline">
        <el-divider content-position="left">基本信息</el-divider>
        <el-form-item prop="F_PKTL_CustomerName" :rules="companyNameRules">
          <span slot="label" class="formLabel">公司全称:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CustomerName" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="公司全称"></el-input>
        </el-form-item>
        <el-form-item>
          <span slot="label" class="formLabel">公司简称:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CustomerShortName" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="公司简称"></el-input>
        </el-form-item>
        <br />
        <el-form-item required>
          <span slot="label" class="formLabel">企业性质:</span>
          <el-select v-model="FirmFormInline.F_PKTL_FirmNature" class="formLabelSelect" :disabled="this.personalInputDisabled2" placeholder="企业性质">
            <el-option v-for="item in firmNatureSelect" :label="item.Caption" :key="item.Value" :value="item.Value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item required>
          <span slot="label" class="formLabel">企业类型:</span>
          <el-select v-model="FirmFormInline.F_PKTL_FirmType" class="formLabelSelect" :disabled="this.personalInputDisabled2" placeholder="企业类型">
            <el-option v-for="item in firmTypeSelect" :label="item.Caption" :key="item.Value" :value="item.Value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="F_PKTL_RegisteredCapital" :rules="moneyRules">
          <span slot="label" class="formLabel">注册资金:</span>
          <el-input v-model="FirmFormInline.F_PKTL_RegisteredCapital" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="注册资金（万元）">
            <template slot="append">万元</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_FoundYear" :rules="yearRules">
          <span slot="label" class="formLabel">成立年份:</span>
          <el-input v-model="FirmFormInline.F_PKTL_FoundYear" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="成立年份（年）">
            <template slot="append">年</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_CorporationName" :rules="userNameRules">
          <span slot="label" class="formLabel">法定代表人:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CorporationName" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="法定代表人"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_CorporationPhone" :rules="PhoneNumberRules" required>
          <span slot="label" class="formLabel">法人联系方式:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CorporationPhone" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="法人联系方式"></el-input>
        </el-form-item>
        <br />
        <el-form-item prop="F_PKTL_BankCard" :rules="bankAccountRules">
          <span slot="label" class="formLabel">银行账号:</span>
          <el-input v-model="FirmFormInline.F_PKTL_BankCard" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="银行账号"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_DepositBank" :rules="depositBankRules">
          <span slot="label" class="formLabel">开户行:</span>
          <el-input v-model="FirmFormInline.F_PKTL_DepositBank" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="开户行"></el-input>
        </el-form-item>
        <br />
        <el-form-item prop="F_PKTL_FirmMail" :rules="mailRules">
          <span slot="label" class="formLabel">企业邮箱:</span>
          <el-input v-model="FirmFormInline.F_PKTL_FirmMail" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="企业邮箱"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_TaxNumber" :rules="taxNumberRules">
          <span slot="label" class="formLabel">税号:</span>
          <el-input v-model="FirmFormInline.F_PKTL_TaxNumber" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="税号"></el-input>
        </el-form-item>
        <!-- <el-form-item>
          <span slot="label" class="formLabel">所属行业:</span>
          <el-input v-model="FirmFormInline.belongTrade"  class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="所属行业"></el-input>
        </el-form-item> -->
        <el-form-item prop="F_PKTL_FirmAddress" :rules="addressRules">
          <span slot="label" class="formLabel">公司办公地址:</span>
          <el-input v-model="FirmFormInline.F_PKTL_FirmAddress" class="formLabelInput2" :disabled="this.personalInputDisabled2" placeholder="xxx省xxx市xxx县+详细地址"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_FactoryAddress" :rules="addressRules">
          <span slot="label" class="formLabel">生产工厂地址:</span>
          <el-input v-model="FirmFormInline.F_PKTL_FactoryAddress" class="formLabelInput2" :disabled="this.personalInputDisabled2" placeholder="xxx省xxx市xxx县+详细地址"></el-input>
        </el-form-item>
        <el-form-item>
          <span slot="label" class="formLabel">经营范围:</span>
          <el-input type="textarea" v-model="FirmFormInline.F_PKTL_ManageScope" class="formLabelInput2" :disabled="this.personalInputDisabled2" placeholder="列举（xx行业）"></el-input>
        </el-form-item>
        <el-form-item>
          <span slot="label" class="formLabel">其他:</span>
          <el-input type="textarea" v-model="FirmFormInline.F_PKTL_FirmOtherDetail" class="formLabelInput2" :disabled="this.personalInputDisabled2" placeholder="企业说明"></el-input>
        </el-form-item>
        <el-divider content-position="left">联系方式</el-divider>
        <el-form-item prop="F_PKTL_CurrentUserName" :rules="userNameRules">
          <span slot="label" class="formLabel">联系人姓名:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CurrentUserName" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="联系人姓名"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_CurrentUserPhone" :rules="PhoneNumberRules">
          <span slot="label" class="formLabel">手机号:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CurrentUserPhone" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item prop="F_PKTL_CurrentUserMail" :rules="mailRules">
          <span slot="label" class="formLabel">邮箱:</span>
          <el-input v-model="FirmFormInline.F_PKTL_CurrentUserMail" class="formLabelInput" :disabled="this.personalInputDisabled2" placeholder="邮箱"></el-input>
        </el-form-item>
        <el-divider content-position="left">附件</el-divider>
         <el-form-item label-width="formLabelWidth">
          <el-upload class="upload-class" ref="fileUpload" action="#" name="资质附件" :file-list="fileList" :http-request="fileUpload" :on-remove="handleRemove" :disabled="this.personalInputDisabled2">
            <el-button size="small" type="primary" :disabled="this.personalInputDisabled2">资质附件</el-button>
          </el-upload>
        </el-form-item>
          </el-form>
        <br />
      </el-form>
      <el-popover placement="top" width="160" v-model="visible2">
        <p>确认修改基本信息吗？</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="text" @click="visible2 = false">取消</el-button>
          <el-button type="primary" size="mini" @click="onFirmSubmit('FirmFormInline')">确定</el-button>
        </div>
        <el-button slot="reference" class="subButton" type="primary" :disabled="personalInputDisabled2">保存</el-button>
      </el-popover>
      <el-button class="subButton" @click="onPersonalEditor2()">编辑</el-button>
      <el-button class="subButton" @click="pageReload()">取消</el-button><br /><br />
      <!-- <el-divider content-position="left"></el-divider> -->
    </el-tab-pane>
    <el-tab-pane>
      <span slot="label" class="tabsLabel">竞价结果</span>
      <div class="auctionResultDiv">
        <div class="fromTeam">
          <el-date-picker
            v-model="fromDateContent"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="small"
            :default-time="['00:00:00', '23:59:59']"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
          <el-select v-model="fromInputSelect" slot="prepend" placeholder="竞标结果选择" size="small" class="fromSelect">
            <el-option v-for="item in bidStatusSelect" :label="item.Caption" :key="item.Value" :value="item.Value"></el-option>
            <el-option label="" value=""></el-option>
          </el-select>
          <el-input placeholder="请输入内容" v-model="fromInputContent" size="small" class="fromInput"> </el-input>
          <el-button slot="append" size="small" icon="el-icon-search" @click="getConditionQuery()"></el-button>
        </div>
        <el-descriptions v-for="(item, i) in bidAuctionResultList" :key="i" :title="item.F_PKTL_ProjectName" class="resultDescriptions">
          <el-descriptions-item label="品名">{{ item.F_PKTL_MaterialName }}</el-descriptions-item>
          <el-descriptions-item label="物料类型">
            {{ getAuctionResultValue(item.F_PKTL_MaterialType, 'F_PKTL_MaterialType') }}
          </el-descriptions-item>
          <el-descriptions-item label="材质">{{ item.F_PKTL_GoodMaterial }}</el-descriptions-item>
          <el-descriptions-item label="规格">{{ item.F_PKTL_MaterialSpec }}</el-descriptions-item>
          <el-descriptions-item label="中标价格">{{ item.F_PKTL_BidAmount }}</el-descriptions-item>
          <el-descriptions-item label="保证金">{{ item.F_PKTL_PledgeAmount }}</el-descriptions-item>
          <el-descriptions-item label="日期">
            {{ getFormatDate(item.F_PKTL_Date) }}
          </el-descriptions-item>
          <el-descriptions-item label="竞标结果">
            {{ getAuctionResultValue(item.F_PKTL_BidStatus, 'F_PKTL_BidStatus') }}
          </el-descriptions-item>
        </el-descriptions>
        <el-pagination background :page-size="resultLimit" layout="prev, pager, next" :total="resultTopRowCount" @current-change="currentPageChange"> </el-pagination>
      </div>
    </el-tab-pane>
    <!-- <el-tab-pane>
      <span slot="label" class="tabsLabel">参标明细</span>
    </el-tab-pane>
    <el-tab-pane>
      <span slot="label" class="tabsLabel">出价记录</span>
    </el-tab-pane> -->
  </el-tabs>
</template>
<script>
import * as validateRules from '@/common/utils/validateRules.js'
import axios from "axios";

export default {
  data() {
    // 密码框验证规则
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else if (value.length < 6) {
        callback(new Error('密码不能低于六位字符'))
      } else {
        callback()
      }
    }
    // 确认密码框验证规则
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.userFormInline.F_PKTL_PassWord) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      // 竞价结果的属性
      // 输入框时间的内容
      fromDateContent: '',
      // 输入框的下拉表单
      fromInputSelect: '',
      // 输入框的内容
      fromInputContent: '',
      // 竞价结果状态的下拉列表
      bidStatusSelect: [],
      // 竞价结果查询的最大行数
      resultLimit: 8,
      // 竞价结果查询的总行数
      resultTopRowCount: 0,
      // 竞价结果查询的开始行索引
      resultStartRow: 0,

      // 账户信息编辑按钮的状态属性
      userDisabled: false,
      // 路由传的参数
      routeQuery: {},
      // 控制输入框（账户和企业信息）是否可以输入内容
      personalInputDisabled1: true,
      personalInputDisabled2: true,
      // 修改密码确认框
      visible1: false,
      visible2: false,
      // 输入框的摆放位置
      tabPosition: 'left',
      // 企业性质下拉框属性
      firmNatureSelect: [],
      // 企业类型下拉框属性
      firmTypeSelect: [],
      // 请求后台的参数
      userInfoParams: {},
      auctionResultParams: {},
      // 金蝶竞价结果公示查询属性数组
      fieldKeys: [
        'FBillNo',
        'F_PKTL_SourceBillNo',
        'F_PKTL_ProjectName',
        'F_PKTL_Date',
        'F_PKTL_MaterialType',
        'F_PKTL_GoodMaterial',
        'F_PKTL_MaterialSpec',
        'F_PKTL_MaterialName',
        'F_PKTL_BidAmount',
        'F_PKTL_PledgeAmount',
        'F_PKTL_BidStatus',
      ],
      // 竞标结果的集合
      bidAuctionResultList: [],
      // 竞价结果的元数据
      resultBusinessInfo: {},
      // 账户信息
      userFormInline: {
        // 内码
        FId: '',
        // 用户名
        F_PKTL_User: '',
        // 密码
        F_PKTL_PassWord: '',
        // 确认密码
        userPasswordCheck: '',
      },
      // 基本信息
      FirmFormInline: {
        // 内码
        FId: '',
        // 公司全称
        F_PKTL_CustomerName: '',
        // 公司简称
        F_PKTL_CustomerShortName: '',
        // 企业性质
        F_PKTL_FirmNature: '',
        // 企业类型
        F_PKTL_FirmType: '',
        // 注册资金
        F_PKTL_RegisteredCapital: '',
        // 成立年份
        F_PKTL_FoundYear: '',
        // 法人代表人
        F_PKTL_CorporationName: '',
        // 法人联系方式
        F_PKTL_CorporationPhone: '',
        // 银行卡号
        F_PKTL_BankCard: '',
        // 开户行
        F_PKTL_DepositBank: '',
        // 企业邮箱
        F_PKTL_FirmMail: '',
        // 税号
        F_PKTL_TaxNumber: '',
        // 公司办公地址
        F_PKTL_FirmAddress: '',
        // 工厂地址
        F_PKTL_FactoryAddress: '',
        // 经营范围
        F_PKTL_ManageScope: '',
        // 其他说明
        F_PKTL_FirmOtherDetail: '',
        // 当前联系人姓名
        F_PKTL_CurrentUserName: '',
        // 当前联系人联系方式
        F_PKTL_CurrentUserPhone: '',
        // 当前联系人邮箱
        F_PKTL_CurrentUserMail: '',
        // 保证金
        // F_PKTL_CautionMoney: "",
        // 账户类型
        F_PKTL_UserType: '',
        // 身份证号码
        F_PKTL_CardID: '',
        // 联系地址
        F_PKTL_ContactAddress: '',
      },
      // 以下为验证规则
      //   用户名规则
      userNameRules: [
        { required: true, message: '内容不能为空', trigger: 'blur' },
        { min: 2, message: '不能低于两个字符', trigger: 'blur' },
      ],
      //   企业名称规则
      companyNameRules: [
        { required: true, message: '内容不能为空', trigger: 'blur' },
        { min: 3, message: '不能低于三个字符', trigger: 'blur' },
      ],
      //   金额验证
      moneyRules: [{ required: true, validator: validateRules.moneyReg, trigger: 'blur' }],
      // 年限规则验证
      yearRules: [{ required: true, validator: validateRules.yearValid, trigger: 'blur' }],
      // 开户行规则
      depositBankRules: [
        { required: true, message: '开户行不能为空', trigger: 'blur' },
        { min: 6, message: '不能低于六个字符', trigger: 'blur' },
      ],
      // 地址填写规则
      addressRules: [
        { required: true, message: '地址不能为空', trigger: 'blur' },
        { min: 8, message: '不能低于八个字符', trigger: 'blur' },
      ],
      //   密码框
      userPasswordRules: [{ validator: validatePass, trigger: 'blur' }],
      //   密码确认框
      userPasswordTrueRules: [{ validator: validatePass2, trigger: 'blur' }],
      // 银行卡号验证
      bankAccountRules: [{ required: true, validator: validateRules.bankAccountValid, trigger: 'blur' }],
      // 邮箱验证
      mailRules: [{ validator: validateRules.validateEmail, trigger: 'blur' }],
      // 税号
      taxNumberRules: [{ required: true, validator: validateRules.validateCreditCode, trigger: 'blur' }],
      // 手机号验证
      PhoneNumberRules: [{ validator: validateRules.validatePhoneNumber, trigger: 'blur' }],
      // 身份证号码验证
      cardIDRules: [{ required: true, validator: validateRules.validateCardID, trigger: 'blur' }],

      fileList:[],
      fileFiledKeys:['FId','FBillType','FInterId','FaliasFileName','FFileId','FAttachmentName','FAttachmentSize','FBillNo','FEntryInterId','FEntryKey'],
      fileParams:{},
    }
  },
  created() {
    // 获取路由传来的参数
    this.routeQuery = this.$route.query
    // 将fid赋值
    this.userFormInline.FId = this.$route.query.curreentUserId
    this.FirmFormInline.FId = this.$route.query.curreentUserId
    // console.log(this.$route.query, '路由传入的fid')
    this.getApiData()
  },
  methods: {
    fileUpload(item){
      let userToken=sessionStorage.getItem('userToken')
      const reader = new FileReader()
      reader.readAsArrayBuffer(item.file)
      reader.onload=()=>{
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
        });
        axios({
          url:this.$_global.uploadUrl+"?filename="+item.file.name+"&fileid="+"&last=true&dbid="+item.file.uid+"&filelen="+item.file.size+"&token="+userToken,
          method:'post',
          data:reader.result,
          timeout:10000
        }).then((res)=>{
          console.log(res)
          loading.close()
          var file={
            name:res.data.Upload2AttachmentResult.FileName,
            FFileId:res.data.Upload2AttachmentResult.FileId,
            FAttachmentSize:item.file.size
          }
          this.fileList.push(file);
        }).catch(err=>{
          alert("文件过大，上传超时")
          console.log(err.code)
          loading.close()
          this.handleRemove(item.file)

        })
      }
    },
    handleRemove(file){
      if(file.FId>0){
        var params={}
            params.FormId="BOS_Attachment"
            params.data={ Ids:file.FId}
          this.$api.file.deleteFile(params).then(res=>{
            this.$message({
                type: 'success',
                message: '删除成功'
              }); 
        })
      }
    },
    buildFileParams(){
      this.fileParams = {}
      this.fileParams.FormId = 'BOS_Attachment'
      this.fileParams.FieldKeys = this.fileFiledKeys.toString()
      this.fileParams.OrderString = 'FId desc'
      this.fileParams.FilterString = [
        { Left: '(', FieldName: 'FInterId', Compare: '=', Value: this.userFormInline.FId, Right: ')', Logic: 'OR' },
      ]
    },
    loadFileList(fileParams){
      let data = { data: fileParams }
      this.$api.file.executeBillQuery(data).then((res) => {
        let files = []
        res.forEach((item, i) => {
            let obj = Object.create(null)
            this.fileFiledKeys.forEach((fieldKey, i) => {
              if(fieldKey=='FAttachmentName'){
                obj['name'] = item[i]
              }
              else{
                obj[fieldKey] = item[i]

              }
            })
            files.push(obj)
        })

        this.fileList=files

        console.log("加载附件")
        console.log(this.fileList)
      })
    },
    // 页面刷新
    pageReload() {
      location.reload()
    },
    // 按顺序获取金蝶的数据
    async getApiData() {
      // 获取表单的元数据
      await this.loadBusinessInfo()
      await this.loadResultBusinessInfo()
      // 初始化金蝶请求参数
      this.buildParams()
      // 请求获取用户数据信息
      this.getUserInfo()
      // 获取竞价结果的数据
      this.buildResultParams()
      this.loadBidAuctionResult(this.auctionResultParams)

      this.buildFileParams()
      this.loadFileList(this.fileParams)
    },
    // 查询竞价结果--初始化金蝶需要的参数
    buildResultParams() {
      if (sessionStorage.getItem('userId') != null) {
        this.auctionResultParams = {}
        this.auctionResultParams.FormId = 'PKTL_BidAuctionResult'
        this.auctionResultParams.FieldKeys = this.fieldKeys.toString()
        this.auctionResultParams.StartRow = this.resultStartRow
        this.auctionResultParams.OrderString = 'F_PKTL_Date desc'
        this.auctionResultParams.FilterString = [{ Left: '(', FieldName: 'F_PKTL_BidCustomerId', Compare: '=', Value: sessionStorage.getItem('userId'), Right: ')', Logic: 'AND' }]
      } else {
        console.log('session中的userid为null')
      }
    },
    // 查询竞价结果--加载
    loadBidAuctionResult(params) {
      params.StartRow = this.resultStartRow
      params.Limit = this.resultLimit
      const data = { data: params }
      this.$api.bidAuctionResult.executeBillQuery(data).then((res) => {
        console.log(res, '竞价结果的数据')
        const notictList = []
        res.forEach((item, i) => {
          let obj = Object.create(null)
          this.fieldKeys.forEach((fieldKey, i) => {
            obj[fieldKey] = item[i]
          })
          notictList.push(obj)
        })
        this.bidAuctionResultList = notictList
        // console.log(this.bidAuctionResultList)
      })
    },
    // 获取竞价结果的元数据
    async loadResultBusinessInfo() {
      await this.$api.billBusinessInfo.queryBusinessInfo('PKTL_BidAuctionResult').then((res) => {
        if (res != null) {
          if (res.Result.NeedReturnData != null) {
            this.resultBusinessInfo = res
            // console.log('竞价结果表单的元数据', this.resultBusinessInfo)
            if (res.Result.NeedReturnData != null) {
              res.Result.NeedReturnData.Entrys[0].Fields.forEach((element) => {
                // 判断元数据的key名字是否符合条件，将数组对象重新赋值
                if (element.Key == 'F_PKTL_BidStatus') {
                  this.bidStatusSelect = element.Extends
                }
              })
            }
          }
        }
      })
    },
    // 获取竞价结果的物料类型
    getAuctionResultValue(fieldValue, fieldKey) {
      return this.Common.getFieldValue(fieldValue, fieldKey, this.resultBusinessInfo)
    },
    // 格式化时间
    getFormatDate(item) {
      return this.Common.dateFormat(item, 'yyyy-MM-dd HH:mm')
    },
    // 获取用户的基本信息--初始化金蝶请求参数
    buildParams() {
      this.userInfoParams = { FormId: '', data: { Id: '' } }
      this.userInfoParams.FormId = 'PKTL_BidCustomer'
      this.userInfoParams.data.Id = this.routeQuery.curreentUserId
    },
    // 金蝶获取用户的基本信息--加载
    getUserInfo() {
      let data = JSON.parse(JSON.stringify(this.userInfoParams))
      this.$api.users.billView(data).then((res) => {
        console.log(res)
        // 属性赋值
        if (res != null) {
          Object.keys(this.FirmFormInline).forEach((element) => {
            if (res.Result.Result[element] != null) {
              this.FirmFormInline[element] = res.Result.Result[element]
              // console.log(element,"--"+this.FirmFormInline[element])
            }
          })
          this.userFormInline.F_PKTL_User = res.Result.Result.F_PKTL_User
          this.userFormInline.F_PKTL_PassWord = res.Result.Result.F_PKTL_PassWord
          console.log(this.FirmFormInline, 'FirmFormInline的内容')
        }
      })
    },
    // 用户的基本信息--金蝶元数据获取方法
    async loadBusinessInfo() {
      await this.$api.billBusinessInfo.queryBusinessInfo('PKTL_BidCustomer').then((res) => {
        // console.log('用户表单的元数据', res)
        res.Result.NeedReturnData.Entrys[0].Fields.forEach((element) => {
          // 判断元数据的key名字是否符合条件，将数组对象重新赋值
          if (element.Key == 'F_PKTL_FirmNature') {
            this.firmNatureSelect = element.Extends
          }
          if (element.Key == 'F_PKTL_FirmType') {
            this.firmTypeSelect = element.Extends
          }
        })
      })
    },
    // 用户表单编辑方法
    onPersonalEditor1() {
      if (this.personalInputDisabled1) {
        this.personalInputDisabled1 = false
      }
    },
    // 公司表单编辑按钮的方法
    onPersonalEditor2() {
      if (this.personalInputDisabled2) {
        this.personalInputDisabled2 = false
      }
    },
    // 修改账户信息的方法
    onUserSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.visible1 = false
          // 拼装数据请求修改接口
          // 初始化发送参数
          const data = { formid: {}, data: { Model: {} } }
          data.formid = 'PKTL_BidCustomer'
          data.data.Model = this.userFormInline
          console.log(data, '修改的请求接口参数')
          this.$api.users.enrollCustomer(data).then((res) => {
            console.log(res)
            // 修改成功
            if (res.Result.ResponseStatus.IsSuccess) {
              sessionStorage.removeItem('userId')
              sessionStorage.removeItem('userNo')
              sessionStorage.removeItem('userName')
              this.$alert('', '登录过期，请重新登录！', {
                confirmButtonText: '确定',
                center: true,
                callback: (action) => {
                  this.$router.push({ name: 'main' })
                  this.$message({
                    type: 'info',
                    message: '请重新登录！',
                  })
                },
              })
            }
          })
        } else {
          this.visible1 = false
          console.log('error submit!!')
          return false
        }
      })
    },
    // 修改基本信息的方法
    onFirmSubmit(formName) {
      if (sessionStorage.getItem('userId') != null) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // 验证通过
            this.visible2 = false
            // 初始化请求数据
            const data = { formid: {}, data: { Model: {} } }
            data.formid = 'PKTL_BidCustomer'
            data.data.Model = this.FirmFormInline
            if(this.fileList.length>0){
              this.$api.users.enrollCustomer(data).then((res) => {
                console.log(res)
                // 修改成功
                if (res.Result.ResponseStatus.IsSuccess) {
                  let modelData=[];
                  this.fileList.forEach(item=>{
                      modelData.push({
                              FId:item.FId,
                              FBillType: "PKTL_BidCustomer",
                              FInterId:res.Result.Id,
                              FaliasFileName:item.filename,
                              FFileId:item.fileId,
                              FAttachmentName:item.name,
                              FAttachmentSize:item.fileSize,
                              FBillNo:res.Result.Number,
                              FEntryInterId:'-1',
                              FEntryKey:' '
                          })
                   
                  })
                  let params={
                    FormId:"BOS_Attachment",
                    data:{
                        NeedUpDateFields:[],
                        BatchCount:2,
                        Model: modelData
                    }}

                  //批量存储附件信息
                  this.$api.file.batchSave(params).then((res)=>{
                    // 注册成功
                    console.log(res.Result.ResponseStatus.IsSuccess, '注册的结果')
                     this.$alert('', '基本信息修改成功！', {
                      confirmButtonText: '确定',
                      center: true,
                      callback: (action) => {
                        this.personalInputDisabled2 = true
                        // location.reload()
                      },
                    })
                  })

                 
                }
              })
            }
            else{
              alert("请上传附件")
            }
          } else {
            this.visible2 = false
            console.log('error submit!!')
            return false
          }
        })
      }else{
        console.log("当前的账户的错误")
      }
    },
    // 条件查询的执行方法
    getConditionQuery() {
      this.auctionResultParams.StartRow = 0
      this.auctionResultParams.FilterString = [{ Left: '(', FieldName: 'F_PKTL_BidCustomerId', Compare: '=', Value: sessionStorage.getItem('userId'), Right: ')', Logic: 'AND' }]
      if (this.fromInputContent != null && this.fromInputContent != '') {
        this.auctionResultParams.FilterString.push(
          { Left: '(', FieldName: 'F_PKTL_SourceBillNo', Compare: 'like', Value: this.fromInputContent, Right: ')', Logic: 'OR' },
          { Left: '(', FieldName: 'F_PKTL_ProjectName', Compare: 'like', Value: this.fromInputContent, Right: ')', Logic: 'AND' }
        )
      }
      if (this.fromInputSelect != '' && this.fromInputSelect != null) {
        this.auctionResultParams.FilterString.push({ Left: '(', FieldName: 'F_PKTL_BidStatus', Compare: 'StatusEqualto', Value: this.fromInputSelect, Right: ')', Logic: 'AND' })
      }
      if (this.fromDateContent != '' && this.fromDateContent != null) {
        this.auctionResultParams.FilterString.push(
          { Left: '(', FieldName: 'F_PKTL_Date', Compare: '>', Value: this.fromDateContent[0], Right: ')', Logic: 'AND' },
          { Left: '(', FieldName: 'F_PKTL_Date', Compare: '<', Value: this.fromDateContent[1], Right: ')', Logic: 'AND' }
        )
      }
      this.getResultCount()
      this.auctionResultParams.Limit = this.resultLimit
      const data = { data: this.auctionResultParams }
      this.$api.bidAuctionResult.executeBillQuery(data).then((res) => {
        console.log(res, '竞价结果的数据')
        const notictList = []
        res.forEach((item, i) => {
          let obj = Object.create(null)
          this.fieldKeys.forEach((fieldKey, i) => {
            obj[fieldKey] = item[i]
          })
          notictList.push(obj)
        })
        this.bidAuctionResultList = []
        this.bidAuctionResultList = notictList
      })
    },
    // 查询竞价结果的总数量
    async getResultCount() {
      this.auctionResultParams.Limit = 0
      const data = { data: this.auctionResultParams }
      await this.$api.bidAuctionResult.executeBillQuery(data).then((res) => {
        console.log(res.length)
        this.resultTopRowCount = res.length
      })
    },
    // 分页的当前页修改触发分方法
    currentPageChange(val) {
      if (val > 0) {
        this.resultStartRow = val * this.resultLimit - this.resultLimit
      }
    },
  },
  // 监听当前页面数值的变化惊醒查询数据
  watch: {
    resultStartRow(newVal, oldVal) {
      if (newVal != oldVal) {
        console.log(newVal, oldVal)
        this.getResultCount()
        // this.buildResultParams()
        this.loadBidAuctionResult(this.auctionResultParams)
      }
    },
  },
}
</script>
<style scoped>
/* 标签页表头样式 */
.tabsLabel {
  margin: 20px;
  font-size: 18px;
  font-weight: 900;
  /* border: 1px solid red; */
}
/* 分割线样式 */
.el-divider {
  height: 30px;
  margin: 10px 0px;
  background-color: rgb(29, 172, 255);
}
.el-divider__text {
  color: rgb(255, 255, 255);
  top: 14px;
  left: 0px;
  background: none;
  font-weight: bold;
}
/* 个人信息表单的样式 */
.demo-form-inline {
  font-size: 0px;
  margin-top: 10px;
}
/* 个人信息的按钮样式 */
.rightButton {
  width: 100px;
}
/* 输入框标题的样式 */
.formLabel {
  font-weight: bold;
}
/* 企业信息的输入框个性设计 */
.formLabelInput {
  width: 440px;
}
.formLabelSelect {
  width: 440px;
}
.formLabelInput2 {
  width: 1000px;
}
/* 按钮的样式 */
.subButton {
  margin-top: 12px;
  margin-left: 20px;
  margin-bottom: 160px;
  float: right;
}
/* 竞价结果的样式 */
.auctionResultDiv {
  height: 1200px;
  padding: 10px;
  margin: auto;
  text-align: center;
  overflow: auto;
  /* border: 1px solid red; */
}
.resultDescriptions {
  margin-bottom: 10px;
  padding: 15px;
  box-shadow: 0 0px 6px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
/* 竞价结果条件查询输入框的样式 */
.fromInput {
  margin-left: 20px;
  width: 600px;
}
.fromSelect {
  margin-left: 20px;
  width: 150px;
}
.fromTeam {
  margin: auto;
  padding-bottom: 15px;
}
</style>
